import 'package:flutter/material.dart';
import 'package:test1/bean/ProductInfo.dart';

class Test_Shopping_Car_List_Item_Page extends StatelessWidget {

  ProductInfo productInfo;
  bool inCart;
  CartChangedCallback cartChangedCallback;

  Test_Shopping_Car_List_Item_Page(this.productInfo, this.inCart,
      this.cartChangedCallback);

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text(productInfo.name, style: getTextStyle(context),),
      leading: new CircleAvatar(
        radius: 25.0,
        backgroundColor: getColor(context),
        child: Text(productInfo.name),
      ),
      onTap: (){
        cartChangedCallback(productInfo,!inCart);
      },
    );
  }

  TextStyle getTextStyle(BuildContext context) {
    if (!inCart) {
      return null;
    }
    return TextStyle(
      color: Colors.black54,
      decoration: TextDecoration.lineThrough,
    );
  }

  Color  getColor(BuildContext context) {
    if(inCart){
      return Colors.black54;
    }else{
      return Theme.of(context).primaryColor;
    }
  }
}

typedef CartChangedCallback(ProductInfo productInfo, bool inCart);